<?php
if(!empty($_POST['submit']))
{
	$time=time();
	$money=$_POST['money']*1;
	
	$sql="select a.userid,b.userid as uid from ".USER." a left join ".EAR." b on a.userid=b.userid 
		where a.user='$_POST[user]'";
	$db->query($sql);
	$re=$db->fetchRow();
	$userid=$re['userid'];
	$uid=$re['uid'];
	if(!empty($userid))
	{
		if(empty($uid))
		{
			$sql="insert into ".EAR." (userid,money,con,admin,time) 
				values ('$userid','$money','$_POST[con]','$_SESSION[ADMIN_USER]','$time')";
			$re=$db->query($sql);
		}
		else
		{
			$sql="update ".EAR." set money='$money',con='$_POST[con]',admin='$_SESSION[ADMIN_USER]',time='$time' 
				where userid='$uid'";
			$re=$db->query($sql);
		}
		
		if($re)
		{
			$sql="update ".USER." set earnest='$money' where userid='$userid'";
			$db->query($sql);
			admin_msg('module.php?m=company&s=earnest_list.php','操作成功');
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE><?php echo lang_show('admin_system');?></TITLE> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../script/prototype.js"></script>
<script type="text/javascript" src="main.js"></script>
</HEAD>
<body>

<div class="bigbox">
	<div class="bigboxhead tb">
		<span class="cbox"><a href="module.php?m=company&s=earnest_list.php">管理保证金</a></span>
		<span class="cbox on"><a href="module.php?m=company&s=earnest_add.php">填加保证金</a></span>
	</div>
	<div class="bigboxbody">
	<form id="form1" name="form1" method="post" action="">
  <table width="100%" border="0" cellpadding="2" cellspacing="0" >
    <tr> 
      <td width="126">会员名  </td>
      <td width="816"><input name="user" type="text" value="<?php echo $_GET['name'];?>" class="text" id="user" /></td>
      </tr>
      <tr> 
        <td>金额</td>
        <td align="left"><input name="money" type="text" class="text" id="money" /></td>
      </tr>
      <tr>
        <td>备注</td>
        <td align="left"><textarea name="con" class="text" id="con"></textarea></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td align="left"><input class="submit" type="submit" name="submit" value="提交" /></td>
      </tr>
  </table>
  </form>
  </div>
</div>
</body>
</html>
